<template>
    <view >
        <view>
            <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="homeSwiper">
                <swiper-item v-for="(item,i) in swiperList" :key="item.goods_id" class="homeSwiperItem">
                    <navigator class="swiper-item" :url="'../../subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
                        <image :src="item.image_src" mode="widthFix"></image>
                    </navigator>
                </swiper-item>
            </swiper>
        </view>
        <view class="navList">
            <view class="navItem" v-for="(item,i) in navList" :key="item.name" @click="navClickHandler(item)">
                <image :src="item.image_src" ></image>
            </view>
        </view>
        <view class="floorList">
            <view class="floorItem" v-for="(item,i) in floorList" :key="item.floor_title">
                <image :src="item.floor_title.image_src" mode="" class="floorTitle"></image>
                <view class="imgBox">
                    <navigator class="leftImgBox" :url="item.product_list[0].url">
                        <image :src="item.product_list[0].image_src" mode="widthFix" :style="{width:item.product_list[0].image_width+'rpx'}"></image>
                    </navigator>
                    <view class="rightImgBox">
                        <navigator  v-for="(img,index) in item.product_list" :key="img.image_src" v-if="index!==0"  :url="img.url" >
                            <image :src="img.image_src" mode="widthFix"  :style="{width:img.image_width+'rpx'}"></image>
                        </navigator>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                swiperList:[],
                navList:[],
                floorList:[]
            };
        },
        onLoad() {
            this.getSwiperList()
            this.getNavList()
            this.getFloorList()
        },
        methods:{
            async getSwiperList(){
                try{
                    const res=await uni.$request.get('/api/public/v1/home/swiperdata')
                    console.log(res)
                    if(res.meta.status!==200){
                        return uni.$showMsg()
                    }
                    this.swiperList=res.message
                }catch(e){
                    uni.$showMsg({title:"网络或服务器异常！"})
                    console.log(e)
                }
            },
            async getNavList(){
                try{
                    const res=await uni.$request.get('/api/public/v1/home/catitems')
                    console.log(res);
                    if(res.meta.status!==200){
                        return uni.$showMsg()
                    }
                    this.navList=res.message
                }catch(e){
                    uni.$showMsg({title:"网络或服务器异常！"})
                    console.log(e)
                }
            },
            async getFloorList(){
                try{
                    const res=await uni.$request.get('/api/public/v1/home/floordata')
                    if(res.meta.status!==200) return uni.$showMsg()
                    res.message.forEach(floor=>{
                        floor.product_list.forEach(prod=>{
                            prod.url='/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
                        })
                    })
                    this.floorList=res.message
                }catch(e){
                    uni.$showMsg({title:"网络或服务器异常!"})
                    console.log(e)
                }
            },
            navClickHandler(item){
                if(item.name=='分类'){
                    uni.switchTab({
                        url:"/pages/cate/cate"
                    })
                }
            }
        },
    }
</script>

<style lang="scss">
.homeSwiper{
    height: 340rpx;
    image{
        width: 100%;
    }
}
.navList{
    display: flex;
    justify-content: space-around;
    margin-top: 15px;
    .navItem{
        image{
            width: 128rpx;
            height: 140rpx;
        }
    }
}
.floorTitle{
    width: 100%;
    height: 60rpx;
}
.imgBox{
    display: flex;
    padding-left: 10rpx;
    .rightImgBox{
        display: flex;
        flex-wrap: wrap;
        justify-content: space-around;
    }
}
</style>
